﻿Shader "Custom/TextureCoordinates/Fog" {
	SubShader{
		Pass {
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			//编译雾效变化时需要。
			#pragma multi_compile_fog

			#include "UnityCG.cginc"

			struct vertexInput {
				float4 vertex : POSITION;
				float4 texcoord0 : TEXCOORD0;
			};

			struct fragmentInput {
				float4 position : SV_POSITION;
				float4 texcoord0 : TEXCOORD0;

				//用于传递雾量，数字应为自由纹理坐标值。
				UNITY_FOG_COORDS(1)
			};

			fragmentInput vert(vertexInput i) {
				fragmentInput o;
				o.position = UnityObjectToClipPos(i.vertex);
				o.texcoord0 = i.texcoord0;

				//从裁剪空间位置计算雾量。
				UNITY_TRANSFER_FOG(o,o.position);
				return o;
			}

			fixed4 frag(fragmentInput i) : SV_Target {
				fixed4 color = fixed4(i.texcoord0.xy,0,0);

			//应用雾效（自动处理附加通道）
			UNITY_APPLY_FOG(i.fogCoord, color);

			//处理可能的另一种自定义雾效颜色选项
			//#ifdef UNITY_PASS_FORWARDADD
			//  UNITY_APPLY_FOG_COLOR(i.fogCoord, color, float4(0,0,0,0));
			//#else
			//  fixed4 myCustomColor = fixed4(0,0,1,0);
			//  UNITY_APPLY_FOG_COLOR(i.fogCoord, color, myCustomColor);
			//#endif

			return color;
		}
		ENDCG
	}
	}
}